﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using CKFinder;


public partial class Admin_AddPhukien : System.Web.UI.Page
{
    PhukienController pPhukienController = new PhukienController();
    DanhmucPhukienController danhmucPhukienController = new DanhmucPhukienController();
    protected void Page_Load(object sender, EventArgs e)
    {

        CKFinder.FileBrowser fb = new FileBrowser();
        fb.BasePath = "../ckfinder/";
        fb.SetupCKEditor(ckeditor);
        ddlLoaiPhukien.DataSource = danhmucPhukienController.GetAll();
        ddlLoaiPhukien.DataTextField = "name";
        ddlLoaiPhukien.DataValueField = "danhmuc_phukien_id";
        ddlLoaiPhukien.DataBind();
    }
    protected void btnSubmit_Click(object sender, EventArgs e)
    {
        Phukien pk = new Phukien();
        pk.Name = txtName.Text;
        pk.DanhmucPhukien_id = Convert.ToInt32(ddlLoaiPhukien.SelectedValue);
        pk.Price_input = Convert.ToSingle(txtPriceInputs.Text);
        pk.Price_output = Convert.ToSingle(txtPriceOutputs.Text);
        pk.Url = txtUrl.Text;
        pk.Description = ckeditor.Text;
        if (ddlStatus.SelectedIndex == 0)
        {
            pk.Status = true;
        }
        else
        {
            pk.Status = false;
        }
        pk.DateStart = DateTime.Now;
        pk.Image = phukien_value.Value;
        int id =pPhukienController.InsertScalar(pk);
        if(id>0)
        {
            if(phukien_image_value.Value!="")
            {
                string str = phukien_image_value.Value.Substring(1);
                char[] s = {','};
                string[] image = str.Split(s);
                foreach (var s1 in image)
                {
                    pPhukienController.InsertImage(id, s1);
                }
            }
            Response.Write("<script>alert('Thêm phụ kiện thành công')</script>");
        }
        else
        {
            Response.Write("<script>alert('Thêm phụ kiện gặp lỗi')</script>");
        }
    }
}